/**
* Created by wl
* 项目管理>持有中-详情页-项目详情-关键协议信息
*/
<template>
    <div class="ca-box ca-m-t-28 ca-p-20">
        <div v-if="!showEdit">
            <div class="ca-title">
                <h3>关键协议</h3>
                <el-button type="text" class="ca-edit-btn el-icon-edit ca-m-r-10 edit-btn" @click="editInfo" :disabled="!isAuthIndexSee">编辑</el-button>
            </div>
            <div class='content_bx'>
                <span>投资风险</span>
                <p>
                    {{itemHoldTextEntity[0].text}}
                </p>
            </div>
            <div class='content_bx'>
                <span>投资亮点</span>
                <p>
                    {{itemHoldTextEntity[1].text}}
                </p>
            </div>
            <div class='content_bx'>
                <span>对赌协议</span>
                <div class="wid-100">
                    <div v-for="(item, index) in gambling" :key="index">
                        <p>
                            <b>{{item.protocolTime == null ? '' : $moment(item.protocolTime).format('YYYY-MM-DD')}}</b> {{item.protocolNote}}
                        </p>
                    </div>
                </div>
            </div>
            <div class='content_bx'>
                <span>回购协议</span>
                <div class="wid-100">
                    <div v-for="(item, index) in buyBack" :key="index">
                        <p>
                            <b>{{item.protocolTime == null ? '' : $moment(item.protocolTime).format('YYYY-MM-DD')}}</b> {{item.protocolNote}}
                        </p>
                    </div>
                </div>
            </div>
            <div class='content_bx'>
                <span>限售条件</span>
                <p>
                    {{itemHoldTextEntity[2].text}}
                </p>
            </div>
            <div class='content_bx'>
                <span>IPO及转持备注</span>
                <p>
                    {{itemHoldTextEntity[3].text}}
                </p>
            </div>
            <div class='content_bx'>
                <span>其他</span>
                <p>
                    {{itemHoldTextEntity[4].text}}
                </p>
            </div>
        </div>
        <csKeyProtocol v-else :showBtn="true" @close="close" @save="save"></csKeyProtocol>
        <csBetting v-if="!showEdit"></csBetting>
    </div>
</template>
<script type="text/ecmascript-6">
    import {api} from '../../api';
    import {STATUS_HTTP_SUCCESS, apiHttp} from '__service/csHttp';
    import { addRemind, isNoAuth } from '__service/utils';
    export default {
        data() {
            return {
                isAuthIndexSee: isNoAuth('持有中项目-项目详情-编辑'),
                showEdit: false,
                gambling: [], //对赌部分
                buyBack: [{
                    disposalMethods: null, //处置方式
                    id: null, //id
                    isTrigger: 0, //是否触发 1:是 0:否
                    itemId: null,  //项目ID
                    protocolNote: '', //协议内容
                    protocolTime: '', //协议时间
                    protocolType: 2, //协议类型 1:对赌协议 2:回购协议
                    triggerNote: '', //触发内容
                    triggerTime: new Date() //触发时间
                }], //回购部分
                itemHoldTextEntity: [
                    { //持有中 - 关键协议 - 投资风险
                        'text': '',
                        'textType': this.$store.state.user.dictionaryMap.protocolTextType[0].id
                    },
                    { //持有中 - 关键协议 - 投资亮点
                        'text': '',
                        'textType': this.$store.state.user.dictionaryMap.protocolTextType[1].id
                    },
                    { //持有中 - 关键协议 - 限售条件
                        'text': '',
                        'textType': this.$store.state.user.dictionaryMap.protocolTextType[2].id
                    },
                    { //持有中 - 关键协议 - ipo及转持备注
                        'text': '',
                        'textType': this.$store.state.user.dictionaryMap.protocolTextType[3].id
                    },
                    { //持有中 - 关键协议 - 其他
                        'text': '',
                        'textType': this.$store.state.user.dictionaryMap.protocolTextType[4].id
                    },
                ], //非对赌回购
            }
        },
        watch: {
        },
        props: {
        },
        mounted() {
            this.getInfo()
        },
        methods: {
            close() {
                this.$emit('sendBetting')
                this.showEdit = false
            },
            async save() {
                this.showEdit = false
                await this.getInfo();
                // 添加小红点
                await addRemind({
                    dataId: this.$route.params.itemId, // 业务id
                    dataTab: 0, // tab页顺序 head 也为0 新建为'-1'
                    dataType: 2, // 1拟投资项目,2已投资项目,3母基金,4拟设立基金,5已设立基金,6客户,7潜在项目
                });
                // 根据第三方组件来调用 父组件中定义的方法 重新获取小红点
                this.$root.Dot.$emit('getDotList');
                // 添加小红点 end
            },
            editInfo() {
                this.showEdit = true;
            },
            getInfo() {
                apiHttp(api.CHECK_PROTOCOL, {itemId: this.$route.params.itemId}).then(ret => {
                    if (ret.resCode === STATUS_HTTP_SUCCESS) {
                        this.gambling = []
                        this.buyBack = []
                        ret.data.itemHoldProtocolEntitys.map(item => {
                            if (item.protocolType === 1) { //对赌
                                this.gambling.push(item)
                            } else if (item.protocolType === 2) { //回购
                                this.buyBack.push(item)
                            }
                        })
                        // 非对赌回购
                        if (ret.data.itemHoldTextEntity.length > 0) {
                            ret.data.itemHoldTextEntity.map((item) => {
                                this.itemHoldTextEntity.map((val,ind) => {
                                    if (item.textType === val.textType) {
                                        this.itemHoldTextEntity[ind].text = item.text
                                        this.itemHoldTextEntity[ind].textType = item.textType
                                    }
                                })
                            })
                        }
                        if (this.buyBack.length <= 0) {
                            this.buyBack = [{
                                disposalMethods: null, //处置方式
                                id: null, //id
                                isTrigger: 0, //是否触发 1:是 0:否
                                itemId: null,  //项目ID
                                protocolNote: '', //协议内容
                                protocolTime: '', //协议时间
                                protocolType: 2, //协议类型 1:对赌协议 2:回购协议
                                triggerNote: '', //触发内容
                                triggerTime: new Date() //触发时间
                            }]
                        }
                        if (this.gambling.length <= 0) {
                            this.gambling = [{
                                disposalMethods: null, //处置方式
                                id: null, //id
                                isTrigger: 0, //是否触发 1:是 0:否
                                itemId: null,  //项目ID
                                protocolNote: '', //协议内容
                                protocolTime: '', //协议时间
                                protocolType: 1, //协议类型 1:对赌协议 2:回购协议
                                triggerNote: '', //触发内容
                                triggerTime: new Date() //触发时间
                            }]
                        }
                    }
                })
            },
        },
        components: {
            csKeyProtocol: require('./edit'),
            csBetting: require('../betting-buy-back/index'),
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.edit-btn {
    float: right;
    cursor: pointer;
}
.keyProtocol {
    border: 1px solid #ccc;
}
.ca-inner {
    display:table-cell;
    vertical-align:middle;
}
.icon i {
    font-size: 20px;
    padding: 15px;
}
.keyProtocol {
    border: none;
}
.el-wid-15 {
    width: 10%;
    text-align: center;
    margin-top: 20px;
    margin: 0 auto;
}
.content_bx {
    display:flex;
    padding: 10px 0;
    align-items:center;
}
.content_bx span {
    width:75px;
    height:75px;
    display:flex;
    justify-content:center;
    align-items:center;
    border-radius:50%;
    background:#eff5fe;
    margin-right: 10px;
    color: #1c8eef;
    text-align: center;
    margin-left: 60px;
}
.content_bx p{
    flex:1;
    line-height: 30px;
    // overflow:hidden;
    // text-overflow:ellipsis;
    // display:-webkit-box;
    // -webkit-line-clamp: 2;
    // -webkit-box-orient:vertical;
    margin-left: 29px;
}
.content_bx p b {
    font-weight: normal;
    padding-right: 20px;
}
.wid-100{
    width: 85%;
}
.wid-100 div {
    margin-bottom: 3px;
}
</style>